using UnityEngine;

public class MonkeyBag : DrawableGameObject
{
    public Texture2D[] attackTextures;
    public GameObject banana;
    public GameObject bananaSpawner;
    private bool isChecked = false;
    private GameObject character;
    public float interval = 9;

    public override void Start()
    {
        character = GameObject.FindWithTag("Player");

        base.SetAnimations(null, null, null, null, attackTextures);
        base.Start();
    }

    public void Update()
    {
        if (Mathf.Abs(character.transform.position.x - transform.position.x) < interval)
        {
            RunAnimation();
        }
        else
        {
            base.StopAnimation();
        }

        if (gameObject.renderer.material.mainTexture == attackTextures[25] && isChecked == false)
        {
            Shoot();
            isChecked = true;
        }

        if (gameObject.renderer.material.mainTexture != attackTextures[25])
        {
            isChecked = false;
        }
    }

    public void RunAnimation()
    {
        base.RunAnimation("Attack", "Loop");
    }

    public void Shoot()
    {
        Instantiate(banana, bananaSpawner.transform.position, Quaternion.identity);
    }
}
